import type { DirectiveBinding } from 'vue'
/**
 * @description demo
<template>
  <div v-clamp:10>点击复制</div> 超过10个显示省略号
  <div v-clamp:['10']>点击复制</div> 超过10个显示省略号
</template>

<script setup>
import { ref } from 'vue'
</script>
 */

const clamp = {
  mounted(el: HTMLElement, binding: DirectiveBinding<string | any>) {
    const wordLen = Number(binding.arg) || 20 // 文字个数，超过隐藏

    if (typeof el.textContent === 'string') {
      el.textContent = `${el.textContent.slice(0, wordLen)}...`
    }
  }
}
export default clamp
